# -*- coding: utf-8 -*-
import scrapy
from movieproject0125.items import Movieproject0125Item

class Movie20210125Spider(scrapy.Spider):
    name = 'movie20210125'
    allowed_domains = ['www.bayiyy.com']
    start_urls = ['http://www.bayiyy.com/dianshiju/']

    def parse(self, response):
        # 实例一个Movieproject0125Item对象
        movie = Movieproject0125Item()
        currentpage_tv_rank=response.xpath('//ul[@class="v_rank clearfix"]')
        for tv_rank_item in currentpage_tv_rank:
            # 获取电视剧名称
            movie['tvname']=tv_rank_item.xpath('./li/span[@class="s_tit"]/a/text()').extract()
            # 获取电视剧链接
            movie['tvurl']=tv_rank_item.xpath('./li/span[@class="s_tit"]/a/@href').extract()
            # 获取电视剧热度排名
            movie['tvnum']=tv_rank_item.xpath('./li/span[@class="s_num"]/text()').extract()
            # 将封装好的电视剧信息添加到容器中,yield作用是创建一个列表并添加元素
            yield movie
            pass
        pass

